<template>
  <a-table
    :columns="columns"
    rowKey="id"
    :dataSource="data"
    bordered
    :loading="loading"
    size="small"
    :title="title"
  >
  </a-table>
</template>

<script>

  import {getAction} from '@/api/manage';
  import YchConstant from "@/api/YchConstant";
  import LocaleUtil from "../../../../utils/LocaleUtil";

  export default {
    name: "BpmIdeaPassRound",
    props: {
      processInstanceId: {
        type: String,
        default: null
      },
      refreshFlg: {
        type: Number,
        default: 0
      },
    },
    components: {},
    data() {
      return {
        url: {
          getData: YchConstant.PREFIX_BPM + "/bpm-front/displayRest/getIdeaPassRoundListByInstanceId/v1"
        },
        data: [],
        loading: false,
        columns: [{
          title:this.$t('m.common.label.number'),
          dataIndex: '',
          key: 'rowIndex',
          width: 50,
          align: "center",
          customRender: function (t, r, index) {
            return parseInt(index) + 1;
          }
        }, {
          title: this.$t('m.bpm.entity.passName'),
          dataIndex: 'userName',
          width: 180,
          align: "center",
          customRender: function (value, row, index) {
            if (row.deptName) {
              return value + "/" + row.deptName;
            }
            return value;
          }
        }, {
          title:this.$t('m.bpm.entity.passType'),
          dataIndex: 'operationTypeString',
          width: 80,
          align: "center"
        }, {
          title: this.$t('m.bpm.entity.passTime'),
          dataIndex: 'endTime',
          width: 130,
          align: "center"
        }, {
          title: this.$t('m.bpm.entity.passMessage'),
          width: 200,
          dataIndex: 'message'
        }],
        title: function () {
          return LocaleUtil.getLocale("m.bpm.design.idea_pass_round_title")
        }
      }
    },
    mounted() {
      this.refresh();
    },
    methods: {
      refresh() {
        if (!this.processInstanceId) {
          return;
        }
        const that = this;
        that.loading = true;
        getAction(this.url.getData, {processInstanceId: this.processInstanceId}).then((res) => {
          if (res.success) {
            that.data = res.result;
          } else {
            that.messageUtil.warning(res.message);
          }
        }).finally(() => {
          that.loading = false;
        });
      }
    },
    watch: {
      refreshFlg(value) {
        if (value > 1) {
          this.refresh();
        }
      }
    }
  }
</script>
